package signAction;

import java.util.*;


import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

import signBean.DbManager;
import signBean.LoginDate;

public class LoginAction extends ActionSupport{
	String uname;
	String password;
	List list;
	public List getList() {
		return list;
	}

	public void setList(List list) {
		this.list = list;
	}
	public String getUname() {
		return uname;
	}

	public void setUname(String uname) {
		this.uname = uname;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}
	
	public String execute(){
		DbManager db = new DbManager();
		if(db.checkUser(uname, password)){
			List list = db.getDate(uname, password);
			Iterator lists = list.iterator();
			lists.hasNext();
			LoginDate la = (LoginDate)lists.next();
			HttpServletRequest  request = ServletActionContext.getRequest();
			request.getSession().setAttribute("name", la.getName());
			request.getSession().setAttribute("id", la.getId());
			request.getSession().setAttribute("auth", la.getAuth());
			if(la.getAuth()==0){
				return "work";
			}else{
				return "admin";
			}

		}else{
			
			return "input";
		}
	}


	
}
